<?php
namespace app\login\controller;

use app\login\model\User;
use think\Controller;
use think\Session;
use think\Request;
use app\login\validate\Doregister;

class Register extends Controller{
    public function register(){
        $hint = Session::get('Hint');
        $this->assign('hint',$hint);
        return $this->fetch();
    }

    public function doregister(){
        if(Request::instance()->isPost()){
            $has = Request::instance()->post();
            var_dump($has);
            $validate = new Doregister();
            if(!$validate->check($has)){
                $hint=$validate->getError();
                Session::set('Hint',$hint);
                $this->redirect('login/Register/register');
            }else{
                $UserModel = new User();
                $user = $UserModel->addUser($has['Account'],$has['UserName'],$has['Password'],$has['userstatus']);
                if($user==1){
                    $this->redirect('login/Login/login'); 
                }else{
                    $hint = $user;
                    Session::set('Hint',$hint);
                    $this->redirect('login/Register/register');
                }
            }
        }
    }
}
?>